Skip to content

ColorsPanel: for loop check condition simplify for optimize#2041

Open
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:optimize-cond-forloops
Open

ColorsPanel: for loop check condition simplify for optimize#2041
GermanAizek wants to merge 1 commit into
htop-dev:mainfrom
GermanAizek:optimize-cond-forloops

Conversation

@GermanAizek

@GermanAizek GermanAizek commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

@natoscott, isn't it easier to check each step in the loops with this PR condition?
Access by index in array heavy operation vs check i index with const var LAST_COLORSCHEME

Clion IDE have diff view Code and Assembly with compiler flags.
Out of interest, I can show how much less x86 instructions it should give on -O3.

Access by index in array heavy operation vs check i index with const var LAST_COLORSCHEME
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 182eeb15-0a78-4448-9bf1-cd06de4b8edf

📥 Commits

Reviewing files that changed from the base of the PR and between 1ef4226 and 673e236.

📒 Files selected for processing (1)
  • ColorsPanel.c

📝 Walkthrough

Walkthrough

Two loops in ColorsPanel.c that iterate over color schemes were changed to use i < LAST_COLORSCHEME as the termination condition instead of checking ColorSchemeNames[i] != NULL. This affects the loop clearing CheckItem states in the event handler and the loop adding CheckItem entries during panel construction.

Changes

File Change Summary
ColorsPanel.c Replaced NULL-sentinel loop condition with LAST_COLORSCHEME bound in two loops (event handler and panel constructor)

Sequence Diagram(s)

Not applicable — this change is a simple loop-bound substitution with no new control flow or interactions to diagram.

Estimated code review effort: Medium

Related issues: None provided

Related PRs: None provided

Suggested labels: bug, cleanup

Suggested reviewers: None provided

Poem

A rabbit hopped through scheme and name,
Chasing NULLs, it wasn't the same.
Now bounded tight by LAST_COLORSCHEME,
No more scanning past the seam.
Hop, hop — the loop runs clean. 🐇


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fasterit

Copy link
Copy Markdown
Member

@GermanAizek: Please show how much runtime / code that change saves.

@fasterit fasterit added the question ❔ Further information is requested label Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

question ❔ Further information is requested

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants